#include "animation.h"
std::ostream& operator << (std::ostream& o, const gemren::animation_context& ac)
{
	if(!ac.enabled)
		o << "from x y z to x y z at x y z frames n1 spp n2 name filename";
	else 
	{
		o << "from "<< ac.start.x << " " << ac.start.y << " " << ac.start.z;
		o << " to "<< ac.end.x << " " << ac.end.y << " " << ac.end.z;
		o << " at "<<ac.center.x<<" "<< ac.center.y<<" "<<ac.center.z;
		o << " frames " << ac.framecnt
		  << " spp "    << ac.spp
		  << " name "   << ac.filename;
	}
	return o;
}

std::istream& operator >> (std::istream& in, gemren::animation_context& ac)
{
	enum {  filled_from = 1,
		filled_to = 2,
		filled_at = 4,
		filled_frames = 8,
		filled_spp = 16,
		filled_name = 32
	};
	int filled = 0;
	std::string prop;
	while(!in.eof())
	{
		in >> prop;
		if(prop == "") break;
		if(prop == "from")
		{
			in >> ac.start.x >> ac.start.y >> ac.start.z;
			filled |= filled_from;
		}
		else if(prop == "to")
		{
			in >> ac.end.x >> ac.end.y >> ac.end.z;
			filled |= filled_to;
		}
		
		else if(prop == "at")
		{
			in >> ac.center.x >> ac.center.y >> ac.center.z;
				filled |= filled_at;
		}

		else if(prop == "frames")
		{	
			in >> ac.framecnt;
			filled |= filled_frames;
		}
		
		else if(prop == "spp")
		{
			in >> ac.spp;
			filled |= filled_spp;
		}
		
		else if(prop == "name")
		{
			in>> ac.filename ;//getline(in, ac.filename);
			filled |= filled_name;
		}

		else
		{
			filled = 0;
			ac.enabled = false;
			break;
		}
		if(in.fail())
		{
			filled = 0;
			ac.enabled = false;
			break;
		}
	}
	if(filled == 0x3F) // all info must be filled in
	{
		ac.enabled = true;
		ac.frameno = 0;
	}
	return in;
}
